<template>
	<!-- 退货管理 -->
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button
					type="primary"
					icon="el-icon-plus"
					@click="add"
				></el-button>
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input
						v-model="searchValue.search"
						placeholder="标题"
						clearable
					></el-input>
					<el-button
						type="primary"
						icon="el-icon-search"
						@click="upsearch"
					></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable
				ref="table"
				:apiObj="apiObj"
				row-key="id"
				stripe
				@row-dblclick="handleRowDblclick"
			>
				<!--         @row-click="handleRowClick"
        :cell-class-name="setCellStyle" -->
				<el-table-column
					label="ID"
					prop="id"
					width="50"
				></el-table-column>
				<el-table-column label="标题" prop="title">
					<template #default="scope">
						<p>{{ scope.row.title.split("-")[1] }}</p>
					</template>
				</el-table-column>
				<el-table-column
					label="采购部门"
					prop="procuredDepartmentName"
					width="200"
				></el-table-column>
				<el-table-column
					label="采购人"
					prop="procuredAdminName"
					width="200"
				></el-table-column>
				<el-table-column
					label="采购时间"
					prop="procuredTime"
					width="200"
				></el-table-column>
				<el-table-column
					label="到货时间"
					prop="arrivalTime"
					width="200"
				></el-table-column>
				<el-table-column
					label="采购金额(元)"
					prop="procuredPrice"
					width="200"
				></el-table-column>
				<el-table-column label="备注" prop="remark"></el-table-column>
				<el-table-column
					label="审核状态"
					prop="status"
					fixed="right"
					width="150"
					sortable
				>
					<template #default="scope">
						<!--0，未审核，1,审核通过，2审核未通过-->
						<p v-if="scope.row.status == 0">待审核</p>
						<p v-if="scope.row.status == 1" style="color: #67c23a">
							通过
						</p>
						<p v-if="scope.row.status == 2" style="color: #f56c6c">
							未通过
						</p>
						<p v-if="scope.row.status == 3" style="color: #ff9b31">
							审核中
						</p>
					</template>
				</el-table-column>
				<el-table-column
					label="操作"
					fixed="right"
					align="center"
					width="250"
				>
					<template #default="scope">
						<el-button-group>
							<el-button
								text
								type="primary"
								size="small"
								@click="table_cancel(scope.row, scope.$index)"
								v-if="scope.row.status == 0"
								>取消退货</el-button
							>
							<el-button
								text
								type="primary"
								size="small"
								@click="table_show(scope.row, scope.$index)"
								>查看</el-button
							>
							<!-- <el-popconfirm
								title="确定作废吗？"
								@confirm="table_del(scope.row, scope.$index)"
								v-if="scope.row.status != 0"
							>
								<template #reference>
									<el-button
										text
										type="primary"
										size="small"
										v-auth-button="['scrap/returnGoods']"
										>作废</el-button
									>
								</template>
							</el-popconfirm> -->
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
</template>
<script>
export default {
	name: "returnGoods",
	data() {
		return {
			apiObj: this.$API.purchase.getReturnGoodsList,
			searchValue: {
				search: null,
			},
			selection: [],
		};
	},

	methods: {
		//添加
		add() {
			this.$router.push({
				path: "/goods/returnGoods/addReturnGoods",
				query: {
					mode: "add",
				},
			});
		},
		// 取消退货
		table_cancel(row) {
			this.$confirm(
				`此操作将取消【${row.procuredCode}】的全部退货, 请问是否继续?`,
				"提示",
				{
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning",
				}
			)
				.then(async () => {
					let res = await this.$API.purchase.cancelReturnGoods.post({
						id: row.id,
					});
					if (res.code == 200) {
						this.$refs.table.refresh();
						this.$message.success("操作成功");
					}
				})
				.catch(() => {
					this.$message({
						type: "info",
						message: "已取消退货",
					});
				});
		},

		//查看
		table_show(row) {
			this.$router.push({
				path: "/goods/returnGoods/returnGoodsDetail",
				query: {
					id: row.id,
				},
			});
		},
		//删除
		async table_del(row) {
			let data = {
				id: row.id,
			};
			var res = await this.$API.purchase.deletePurchaseRequest.post(data);
			if (res.code == 200) {
				this.$refs.table.refresh();
				this.$message.success("操作成功");
			}
		},

		//搜索
		upsearch() {
			this.$refs.table.upData(this.searchValue);
		},

		// 双击表格
		handleRowDblclick(row) {
			this.table_show(row);
		},
	},
};
</script>

<style></style>
